package com.carreirati.evaluation.domain;

import java.util.List;
import javax.persistence.TypedQuery;
import org.springframework.roo.addon.dbre.RooDbManaged;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord;
import org.springframework.roo.addon.json.RooJson;
import org.springframework.roo.addon.tostring.RooToString;

@RooJavaBean
@RooJpaActiveRecord(identifierType = VwGetEvaluationResultsByQuestionParameterPK.class, versionField = "", table = "vw_get_evaluation_results_by_question_parameter", schema = "dbo")
@RooDbManaged(automaticallyDelete = true)
@RooJson
public class VwGetEvaluationResultsByQuestionParameter {

    public static List<com.carreirati.evaluation.domain.VwGetEvaluationResultsByQuestionParameter> findAllVwGetEvaluationResultsByQuestionParameters(long appraisalId, long questionId) {
        String sqlString = "SELECT o.* FROM Vw_Get_Evaluation_Results_By_Question_Parameter o WHERE appraisal_Id = '"+ appraisalId+ "' AND question_Id = '"+ questionId+"' ORDER BY o.grupo";
    	
        return entityManager().createNativeQuery(sqlString, VwGetEvaluationResultsByQuestionParameter.class).getResultList();
    }

    public static List<com.carreirati.evaluation.domain.VwGetEvaluationResultsByQuestionParameter> findAllVwGetEvaluationResultsByQuestionParameterId(long appraisalId, long questionId, long parameterId) {
        TypedQuery<VwGetEvaluationResultsByQuestionParameter> q = entityManager().createQuery("SELECT o FROM VwGetEvaluationResultsByQuestionParameter o WHERE o.id.appraisalId = :appraisalId AND o.id.questionId = :questionId AND o.id.chosenQuestionParamId = :parameterId", VwGetEvaluationResultsByQuestionParameter.class);
        q.setParameter("appraisalId", appraisalId);
        q.setParameter("questionId", questionId);
        q.setParameter("parameterId", parameterId);
        
        return q.getResultList();
    }

    
    public static long countVwGetEvaluationResultsByQuestionParameters() {
        return entityManager().createQuery("SELECT COUNT(*) FROM VwGetEvaluationResultsByQuestionParameter o", Long.class).getSingleResult();
    }
}
